//
//  SwitchUI.swift
//  uiKit-demo
//
//  Created by 陈澎 on 2024/12/24.
//
import UIKit
import Foundation

class MySwitchUI: UIViewController {
    @objc func change(swi:UISwitch) {
        print("开关状态\(swi.isOn)")
    }
    func render(_ self: AnyObject, target: Any) {
        let swi = UISwitch()
        swi.center = CGPoint(x: 40, y: 940)
        // 设置开启状态的颜色
        swi.onTintColor = UIColor.green
        // 普通状态的颜色
        swi.tintColor = UIColor.red
        // 设置滑块的颜色
        swi.thumbTintColor = UIColor.purple
        // 设置开关的初始状态
        swi.isOn = true
        swi.addTarget(target, action: #selector(MySwitchUI.change), for: UIControl.Event.valueChanged)
        self.addSubview(swi)
    }
}
